package com.mzy.linear_struct.面试150题;

/**
 * @Author: mizy3
 * @Date: 2024/08/15/下午3:17
 * @Description:
 */
public class Pro198打家劫舍 {
    public int rob(int[] nums) {
        int[] dp = new int[nums.length];

        // 1 2 3 1
        dp[0] = nums[0]; // 1
        dp[1] = Math.max(nums[1], nums[0]); // 2

        System.out.println(dp[0]+ " ");
        System.out.println(dp[1] + " ");
        for (int i = 2; i < dp.length; i++) {
            dp[i] = Math.max(dp[i - 1], dp[i - 2] + nums[i]);
            System.out.println(dp[i] + " ");
        }

        return dp[nums.length - 1];
    }

    public static void main(String[] args) {
        new Pro198打家劫舍().rob(new int[]{2,1,1,2});
    }
}
